import Data.List

primes :: [Integer]
primes = 2 : filter ( (==1) . length . primeFactors ) [3,5..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
	where
	factor n (p:ps)
		| p*p > n		 = [n]
		| n `mod` p == 0 = p : factor ( n `div` p )	(p:ps)
		| otherwise		 = factor n ps
		
euler_047 = 
	let hasFourDistinctFactors x = 
		(4 == (length.nub.primeFactors) x) 
	in 
	head (filter (\x->(and $ map hasFourDistinctFactors $ take 4 [x..])) [1..])